﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace Runda.CMS.Dal
{
    public partial class SysDesktopWebPartsDal
    {
        public DataTable getPubliDesktopWebParts() {
            string sql = "SELECT WPName,URL,Sequence,URL,CASE WHEN Target IS NULL THEN '' ELSE Target END AS Target FROM Cms_Sys_DesktopWebParts WHERE DesktopID = (select top 1 DesktopID from Cms_Sys_Desktop where ispublic=1 order by IsDefault desc) AND WPType = '0000029901' ORDER BY Sequence";
            DbCommand dbcommand = CurrentDatabase.GetSqlStringCommand(sql);          
            return CurrentDatabase.ExecuteDataSet(dbcommand).Tables[0];
        }

        public DataTable getPrivateDesktopWebParts(Guid UserID) {
            string sql = "SELECT WPName,URL,Sequence,URL,CASE WHEN Target IS NULL THEN '' ELSE Target END AS Target FROM Cms_Sys_DesktopWebParts WHERE DesktopID = (select top 1 DesktopID from Cms_Sys_Desktop where Owner=@UserID or Owner is null order by IsDefault desc,IsPublic) AND WPType = '0000029901' ORDER BY Sequence";

            DbCommand dbcommand = CurrentDatabase.GetSqlStringCommand(sql);
            CurrentDatabase.AddInParameter(dbcommand, "@UserID", DbType.Guid, UserID);
            return CurrentDatabase.ExecuteDataSet(dbcommand).Tables[0];
        }
    }
}
